//Complex.cpp
#include <iostream>
#include "Complex.h"
using namespace std;

Complex::Complex(double re, double im):real(re), imag(im) {

}

void Complex::SetComplex(double re, double im) {
    this->real = re;
    this->imag = im;
}

double Complex::GetReal() {
    return this->real;
}

double Complex::GetImag() {
    return this->imag;
}

Complex Complex::operator+(Complex &c) {
    Complex temp(this->real + c.real, this->imag + c.imag);
    return temp;
}

Complex Complex::operator-(Complex &c) {
    Complex temp(this->real - c.real, this->imag - c.imag);
    return temp;
}

ostream &operator<<(ostream &os, Complex &c) {
    if (c.GetReal() == 0) {
        if (c.GetImag() == 0) { //实部虚部都为0
            //(0)
            os << "(" << 0 << ")";
        } else {    //实部为0虚部不为0
            //(-|""abs(imag)i)
            os << "(" << (c.GetImag() > 0 ? "" : "-") 
            << (c.GetImag() > 0 ? c.GetImag() : -c.GetImag()) << "i)";
        }
    } else {
        if (c.GetImag() == 0) { //实部不为0虚部为0
            //(real)
            os << "(" << c.GetReal() << ")";
        } else {//实部虚部都不为0
            os << "(" << c.GetReal() << (c.GetImag() > 0 ? "+" : "-") 
            << (c.GetImag() > 0 ? c.GetImag() : -c.GetImag()) << "i)";
        }
    }
    return os;
}